import React, {useState} from 'react';
import X6 from '@/component/x6';
import {Radio} from 'antd';
import {initData, initData1} from '@/component/x6/testdata';

interface Node {
  name: string; // 名称
  key: string; // 唯一的
  children?: Node[]; // 字迹
  show: boolean; // 是否显示
}

const nodes: Node[] = [
  {
    name: '商品模块',
    key: 'goods',
    show: true,
    children: [
      {
        name: '充电桩管理1',
        key: 'goods1',
        show: true,
        children: [
          {
            name: '删除',
            key: 'delete',
            show: true,
          }
        ]
      },
      {
        name: '充电桩管理2',
        key: 'goods2',
        show: true,
        children: [
          {
            name: '删除',
            key: 'delete',
            show: true,
          }
        ]
      },
    ]
  }
];

export default function Page() {
  const [loading, setLoading] = useState<boolean>();
  const [data, setData] = useState<any>(initData);

  const map: any = {
    1: initData,
    2: initData1,
  };

  function onChange(e: any) {
    setTimeout(() => {
      setLoading(false);
      setData(map[e.target.value]);
    }, 3000);
    setLoading(true);
  }

  return (
    <>
      <Radio.Group onChange={onChange}>
        <Radio value={1}>A</Radio>
        <Radio value={2}>B</Radio>
      </Radio.Group>
      <X6 data={data} loading={loading}/>
    </>
  );
}
